/**   
 * @文件名称: LoginAction.java
 * @类路径: com.lxj.cms.reception.action
 * @描述: TODO
 * @公司：昆明天度网络信息科技有限公司
 * @作者：李兴建
 * @时间：2013-8-12 下午04:16:07
 * @版本：V1.0   
 */

package com.lxj.cms.reception.action;

import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.lxj.cms.manage.entity.TgMemberEntity;
import com.lxj.cms.reception.action.member.MemberBaseAction;
import com.lxj.core.action.BaseAction;
import com.opensymphony.xwork2.ActionContext;

/**
 * @类功能说明：
 * @类修改者：
 * @修改日期：
 * @修改说明：
 * @公司：昆明天度网络信息科技有限公司
 * @作者：李兴建
 * @创建时间：2013-8-12 下午04:16:07
 * @版本：V1.0
 */
@Namespace(value = "/")
@Results( { @Result(name = "login", location = "/login.jsp"), @Result(name = "member", type = "redirect", location = "/member/member.action") })
//@InterceptorRefs({@InterceptorRef(value="token",params={"includeMethods","login"}),@InterceptorRef("defaultStack")})
public class LoginAction extends BaseAction {
	private static final long serialVersionUID = 5760826880758108382L;

	private String loginName;
	private String password;

	@Override
	public String execute() throws Exception {
		return "login";
	}

	public String login() {
		Criteria criteria = this.createCriteria(TgMemberEntity.class);
		criteria.add(Restrictions.eq("loginName", loginName));
		criteria.add(Restrictions.eq("password", password));
		if (criteria.list().size() > 0) {
			TgMemberEntity currUser = (TgMemberEntity) criteria.list().get(0);
			ActionContext.getContext().getSession().put(MemberBaseAction.currentMemberTag, currUser);
			return "member";
		} else {
			this.addFieldError("loginError", "用户名或密码不正确");
			return "login";
		}

	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
